import React from 'react';

// 路由配置类型
export interface RouteConfig {
  path: string;
  component: React.ComponentType<any>;
  exact?: boolean;
  redirect?: string;
  meta?: {
    title?: string;
    requireAuth?: boolean;
    permission?: string;
  };
}

// 页面组件懒加载配置
export const pageComponents = {
  // 仪表盘
  Dashboard: React.lazy(() => import('@/pages/Dashboard')),
  
  // 用户管理
  UserList: React.lazy(() => import('@/pages/User/list')),
  UserRoles: React.lazy(() => import('@/pages/User/Roles')),
  
  // 产品管理
  ProductList: React.lazy(() => import('@/pages/Products/List')),
  ProductConfigs: React.lazy(() => import('@/pages/Products/Configs')),
  ProductCategories: React.lazy(() => import('@/pages/Products/Categories')),
  ProductBrands: React.lazy(() => import('@/pages/Products/Brands')),
  ProductStatistics: React.lazy(() => import('@/pages/Products/Statistics')),
  
  // 聊天管理
  AiChat: React.lazy(() => import('@/pages/Chat/AiChat')),
  NormalChat: React.lazy(() => import('@/pages/Chat/NormalChat')),
  
  // 订单管理
  OrderList: React.lazy(() => import('@/pages/Orders/List')),
  
  // 系统管理
  SystemConfig: React.lazy(() => import('@/pages/System/Config')),
  SystemLogs: React.lazy(() => import('@/pages/System/Logs')),
  
  // 错误页面
  NotFound: React.lazy(() => import('@/pages/NotFound')),
};

// 路由配置
export const routeConfigs: RouteConfig[] = [
  // 默认重定向
  {
    path: '/',
    redirect: '/dashboard',
    component: pageComponents.Dashboard,
    exact: true,
  },
  
  // 仪表盘
  {
    path: '/dashboard',
    component: pageComponents.Dashboard,
    meta: {
      title: '仪表盘',
      requireAuth: true,
    },
  },
  
  // 用户管理
  {
    path: '/user/list',
    component: pageComponents.UserList,
    meta: {
      title: '用户列表',
      requireAuth: true,
    },
  },
  {
    path: '/user/roles',
    component: pageComponents.UserRoles,
    meta: {
      title: '角色权限',
      requireAuth: true,
    },
  },
  
  // 产品管理
  {
    path: '/products/list',
    component: pageComponents.ProductList,
    meta: {
      title: '产品列表',
      requireAuth: true,
    },
  },
  {
    path: '/products/configs',
    component: pageComponents.ProductConfigs,
    meta: {
      title: '配置管理',
      requireAuth: true,
    },
  },
  {
    path: '/products/categories',
    component: pageComponents.ProductCategories,
    meta: {
      title: '类别管理',
      requireAuth: true,
    },
  },
  {
    path: '/products/brands',
    component: pageComponents.ProductBrands,
    meta: {
      title: '品牌管理',
      requireAuth: true,
    },
  },
  {
    path: '/products/statistics',
    component: pageComponents.ProductStatistics,
    meta: {
      title: '产品统计',
      requireAuth: true,
    },
  },
  
  // 聊天管理
  {
    path: '/chat/ai-chat',
    component: pageComponents.AiChat,
    meta: {
      title: 'AI对话管理',
      requireAuth: true,
    },
  },
  {
    path: '/chat/normal-chat',
    component: pageComponents.NormalChat,
    meta: {
      title: '普通对话管理',
      requireAuth: true,
    },
  },
  
  // 订单管理
  {
    path: '/orders/list',
    component: pageComponents.OrderList,
    meta: {
      title: '订单列表',
      requireAuth: true,
    },
  },
  
  // 系统管理
  {
    path: '/system/config',
    component: pageComponents.SystemConfig,
    meta: {
      title: '系统配置',
      requireAuth: true,
    },
  },
  {
    path: '/system/logs',
    component: pageComponents.SystemLogs,
    meta: {
      title: '系统日志',
      requireAuth: true,
    },
  },
  
  // 404页面
  {
    path: '*',
    component: pageComponents.NotFound,
    meta: {
      title: '页面未找到',
      requireAuth: true,
    },
  },
];

// 根据路径获取路由配置
export const getRouteConfig = (path: string): RouteConfig | undefined => {
  return routeConfigs.find(route => route.path === path);
};

// 获取所有需要认证的路由
export const getAuthRoutes = (): RouteConfig[] => {
  return routeConfigs.filter(route => route.meta?.requireAuth);
};

// 获取所有公开路由
export const getPublicRoutes = (): RouteConfig[] => {
  return routeConfigs.filter(route => !route.meta?.requireAuth);
}; 